package com.rm.zeyou.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.github.pagehelper.PageInfo;
import com.rm.zeyou.annotation.RepeatSubmit;
import com.rm.zeyou.entity.User;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.UserItemOrderService;
import com.rm.zeyou.util.login.LoginUtil;
import com.rm.zeyou.vo.request.*;
import com.rm.zeyou.vo.response.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 * <p>
 * 用户订单表 前端控制器
 * </p>
 *
 * @author YanYang
 * @since 2025-03-12 15:55:09
 */
@Api(tags = "用户订单相关")
@RestController
@RequestMapping("/api/userItemOrder")
public class UserItemOrderController {
    @Resource
    private UserItemOrderService userItemOrderService;
    @Resource
    private LoginUtil loginUtil;


    @ApiOperation("创建订单详情")
    @PostMapping("createOrderDetail")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<CreateOrderResponseVo> createOrderDetail(@RequestBody CreateOrderVo createOrderVo) throws ParseException {
        User user = loginUtil.getUser();
        return userItemOrderService.createOrderDetail(user.getId(), createOrderVo);
    }

    @ApiOperation("创建订单")
    @PostMapping("createOrder")
    @SaCheckLogin(type = "user")
    @RepeatSubmit(timeout = 500)
    public ApiRestResponse createOrder(@RequestBody CreateOrderVo createOrderVo) throws Exception {
        User user = loginUtil.getUser();
        return userItemOrderService.createOrder(user, createOrderVo);
    }

    @ApiOperation("支付订单")
    @PostMapping("payOrder")
    @SaCheckLogin(type = "user")
    @RepeatSubmit(timeout = 500)
    public ApiRestResponse payOrder(@RequestBody PayOrderRequestVo requestVo) throws Exception {
        User user = loginUtil.getUser();
        requestVo.setUser(user);
        return userItemOrderService.payOrder( requestVo);
    }

    @ApiOperation("取消订单")
    @GetMapping("cancelOrder")
    @SaCheckLogin(type = "user")
    @RepeatSubmit(timeout = 500)
    public ApiRestResponse cancelOrder(@RequestParam String orderNo) throws Exception {
        User user = loginUtil.getUser();
        return userItemOrderService.cancelOrder(user, orderNo);
    }

    @ApiOperation("待接单取消订单")
    @GetMapping("userCancelOrder")
    @SaCheckLogin(type = "user")
    @RepeatSubmit(timeout = 500)
    public ApiRestResponse userCancelOrder(@RequestParam String orderNo) throws Exception {
        User user = loginUtil.getUser();
        return userItemOrderService.userCancelOrder(user, orderNo);
    }

    @ApiOperation("用户查看订单列表")
    @PostMapping("selectUserItemOrderList")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<PageInfo<SelectUserItemOrderListResponseVo>> selectUserItemOrderList(@RequestBody SelectUserItemOrderListVo requestVo)  {
        User user = loginUtil.getUser();
        return userItemOrderService.selectUserItemOrderList(user.getId(), requestVo);
    }

    @ApiOperation("用户查看订单详情")
    @GetMapping("selectUserItemOrderDetail")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<SelectUserItemOrderDetailResponseVo> selectUserItemOrderDetail(@RequestParam String orderNo)  {
        User user = loginUtil.getUser();
        return userItemOrderService.selectUserItemOrderDetail(user.getId(), orderNo);
    }

    @ApiOperation("用户更换技师创建订单详情")
    @PostMapping("replaceTechnicianCreateOrderDetail")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<CreateOrderResponseVo> replaceTechnicianCreateOrderDetail(@RequestBody CreateOrderVo createOrderVo) throws ParseException {
        User user = loginUtil.getUser();
        return userItemOrderService.replaceTechnicianCreateOrderDetail(user.getId(), createOrderVo);
    }

    @ApiOperation("用户更换技师创建订单")
    @PostMapping("replaceTechnicianCreateOrder")
    @SaCheckLogin(type = "user")
    @RepeatSubmit(timeout = 500)
    public ApiRestResponse replaceTechnicianCreateOrder(@RequestBody CreateOrderVo createOrderVo) throws Exception {
        User user = loginUtil.getUser();
        return userItemOrderService.replaceTechnicianCreateOrder(user, createOrderVo);
    }

    @ApiOperation("确认结束订单")
    @PostMapping("confirmOrder")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> confirmOrder(@RequestBody ConfirmOrderVo confirmOrderVo) throws Exception {
        User user = loginUtil.getUser();
        return userItemOrderService.confirmOrder(user.getId(), confirmOrderVo);
    }


    @ApiOperation("评价订单")
    @PostMapping("userAppraiseOrder")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> userAppraiseOrder(@RequestBody UserAppraiseOrderVo appraiseVo)  {
        User user = loginUtil.getUser();
        return userItemOrderService.userAppraiseOrder(user.getId(), appraiseVo);
    }

    @ApiOperation("删除订单")
    @PostMapping("userDeleteOrder")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> userDeleteOrder(@RequestBody UserDeleteOrderVo deleteVo)  {
        return userItemOrderService.userDeleteOrder(deleteVo);
    }

    @ApiOperation("升级套餐详情")
    @PostMapping("userUpgradeOrderDetail")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<UserUpgradeOrderDetailResponseVo> userUpgradeOrderDetail(@RequestBody UserUpgradeOrderDetailVo upgradeOrderDetailVo)  {
        User user = loginUtil.getUser();
        return userItemOrderService.userUpgradeOrderDetail(user.getId(),upgradeOrderDetailVo);
    }

    @ApiOperation("升级套餐")
    @PostMapping("userUpgradeOrder")
    @SaCheckLogin(type = "user")
    @RepeatSubmit(timeout = 500)
    public ApiRestResponse userUpgradeOrder(@RequestBody UserUpgradeOrderVo upgradeOrderVo) throws Exception {
        User user = loginUtil.getUser();
        return userItemOrderService.userUpgradeOrder(user,upgradeOrderVo);
    }

    @ApiOperation("升级套餐订单支付")
    @PostMapping("userUpgradeOrderPay")
    @SaCheckLogin(type = "user")
    @RepeatSubmit(timeout = 500)
    public ApiRestResponse userUpgradeOrderPay(@RequestBody PayOrderRequestVo requestVo) throws Exception {
        User user = loginUtil.getUser();
        requestVo.setUser(user);
        return userItemOrderService.upgradePayOrder(requestVo);
    }

    @ApiOperation("升级套餐订单取消支付")
    @GetMapping("userUpgradeOrderCancelPay")
    @SaCheckLogin(type = "user")
    public ApiRestResponse userUpgradeOrderCancelPay( @RequestParam String orderNo) {
        return userItemOrderService.userUpgradeOrderCancelPay(orderNo);
    }

    @ApiOperation("加钟订单详情")
    @PostMapping("userBellOrderDetail")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<UserBellOrderDetailResponseVo> userBellOrderDetail(@RequestBody UserBellOrderDetailVo userBellOrderDetailVo)  {
        User user = loginUtil.getUser();
        return userItemOrderService.userBellOrderDetail(user.getId(),userBellOrderDetailVo);
    }


    @ApiOperation("加钟订单")
    @PostMapping("userBellOrder")
    @SaCheckLogin(type = "user")
    @RepeatSubmit(timeout = 500)
    public ApiRestResponse userBellOrder(@RequestBody UserBellOrderVo userBellOrderVo) throws Exception {
        User user = loginUtil.getUser();
        return userItemOrderService.userBellOrder(user,userBellOrderVo);
    }




    @ApiOperation("加钟订单支付")
    @PostMapping("bellPayOrder")
    @SaCheckLogin(type = "user")
    @RepeatSubmit(timeout = 500)
    public ApiRestResponse bellPayOrder(@RequestBody PayOrderRequestVo requestVo) throws Exception {
        User user = loginUtil.getUser();
        requestVo.setUser(user);
        return userItemOrderService.bellPayOrder(requestVo);
    }

    @ApiOperation("加钟订单取消支付")
    @GetMapping("bellOrderCancelPay")
    @SaCheckLogin(type = "user")
    public ApiRestResponse bellOrderCancelPay( @RequestParam String orderNo) {
        return userItemOrderService.bellOrderCancelPay(orderNo);
    }

}
